﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WeiBo.SinaAPI;
namespace TCS.Web.MembersHome
{
    public partial class BindWb : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           int Member_ID = Convert.ToInt32(Request.Params["u"]);
         
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (WeiBo.SinaAPI.SinaBase.User != null)
            {
                oAuthSina oauth = SinaBase.oAuth;
                int Member_ID = 0;
                Member_ID = Convert.ToInt32(Request.Params["u"]);
                string oauth_token = oauth.Token;
                string oauth_token_secret = oauth.TokenSecret;
                long wb_id = -1;
                string WB_AccountName = "";
                string WB_NickName = "";
                string WB_Name = "";
                string WB_ProvinceID = "";
                string WB_CityID = "";
                string WB_Location = "";
                string WB_Gender = "";
                string WB_Author = "";
                if (WeiBo.SinaAPI.SinaBase.User != null)
                {
                    WeiBo.SinaAPI.SinaMUsers user = WeiBo.SinaAPI.SinaBase.User;
                    wb_id = user.id;
                    WB_AccountName = user.name;
                    WB_NickName = user.screen_name;
                    WB_Name = user.name;
                    WB_ProvinceID = user.province;
                    WB_CityID = user.city;
                    WB_Location = user.location;
                    WB_Gender = user.gender;
                 

                }
                TCS.Model.Weibo.WeiBo_UserInfo model = new TCS.Model.Weibo.WeiBo_UserInfo();
                model.WB_AccountName = WB_AccountName;
                model.WB_Pwd = "";
                model.WB_NickName = WB_NickName;
                model.Member_ID = Member_ID;
                model.WB_Name = WB_Name;
                model.WB_ProvinceID = int.Parse(WB_ProvinceID);
                model.WB_CityID = int.Parse(WB_CityID);
                model.WB_Location = WB_Location;
                model.WB_Gender = WB_Gender;
                model.WB_Author = 0;
                model.oauth_token = oauth_token;
                model.oauth_token_secret = oauth_token_secret;
                model.Wb_id =wb_id;
                TCS.BLL.Weibo.WeiBo_UserInfo bll = new TCS.BLL.Weibo.WeiBo_UserInfo();
                if (bll.GetModel(wb_id) == null)
                {
                    bll.Add(model);
                    this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('已成功绑定账号！');location.href='main.aspx?u=" + Member_ID.ToString() + "';</script>");
                }
                else
                {
                    LTP.Common.MessageBox.ShowAndRedirects(this, "该账号已经绑定过了！", "login.aspx");
                }
               

               
            }
        }
    }
}
